1
2
3
4
5
6 package ch.twiddlefinger.inet.rewinder.model.parser.conversion;
7
8 import java.nio.ByteBuffer;
9
10
11 /***
12 * <p> This class represents a <code>C/C++ union</code>; it works in the same
13 * way as {@link Struct} (sub-class) except that all members are mapped
14 * to the same location in memory.</p>
15 * <p> Here is an example of C union: <pre>
16 * union Number {
17 * int asInt;
18 * float asFloat;
19 * char asString[12];
20 * };</pre>
21 * And its Java equivalent:<pre>
22 * public class Number extends Union {
23 * Signed32 asInt = new Signed32();
24 * Float32 asFloat = new Float32();
25 * UTF8String asString = new UTF8String(12);
26 * }</pre>
27 * As for any {@link Struct}, fields are directly accessible:<pre>
28 * Number num = new Number();
29 * num.asInt.set(23);
30 * num.asString.set("23"); // Null terminated (C compatible)
31 * float f = num.asFloat.get();</pre>
32 *
33 * <p><i> This class is <b>public domain</b> (not copyrighted).</i></p>
34 *
35 * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
36 * @version 5.2, September 28, 2003
37 */
38 public class Union extends Struct {
39 /***
40 * Default constructor. Top-level {@link Union} created using this
41 * constructor are backed by a non-direct buffer allocated on the heap.
42 * Inner {@link Struct} are always backed by the buffer of their outer
43 * parent.
44 */
45 public Union() {
46 super();
47 }
48
49 /***
50 * Creates a {@link Union} backed by the specified {@link ByteBuffer}.
51 * This constructor allows for the use of direct buffers (e.g. mapped
52 * to memory).
53 *
54 * @param buffer the data buffer for this {@link Union}.
55 */
56 public Union(ByteBuffer buffer) {
57 super(buffer);
58 }
59
60
61
62
63 }